package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.dto.StudentQueryDto;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    StudentService studentService;

    /*添加学员*/
    @Log
    @PostMapping
    public R insert(@RequestBody Student student) {
        studentService.insert(student);
        return R.ok();
    }


    @GetMapping()
    public R StudentQuery(StudentQueryDto dto) {
        PageBean pageBean = studentService.StudentQuery(dto);
        return R.ok(pageBean);
    }

    /*根据id查*/
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        Student student = studentService.getById(id);
        return R.ok(student);
    }

    @Log
    @DeleteMapping("/{ids}")
    public R delete(@PathVariable List<Integer> ids) {
        studentService.delete(ids);
        return R.ok();
    }

    /*修改*/
    @Log
    @PutMapping
    public R update(@RequestBody Student student) {
        studentService.update(student);
        return R.ok();
    }
    /*违纪处理*/
    @Log
    @PutMapping("/violation/{id}/{score}")
    public R violation(@PathVariable Integer id,@PathVariable Integer score) {
        studentService.violation(id,score);
        return R.ok();
    }

}

